package com.example.admin.controller.web.system;

import java.util.Arrays;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.common.system.entity.MenuEntity;
import com.example.common.system.service.MenuService;
import com.example.common.util.PageUtils;
import com.example.common.core.response.AjaxResult;



/**
 * 菜单权限表
 *
 * @author chen
 * @email 17635014889@163.com
 * @date 2022-09-21 15:07:55
 */
@RestController
@RequestMapping("/system/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("@ss.hasPerm('system:menu:list')")
    public AjaxResult list(Page<MenuEntity> page,MenuEntity menuEntity){
        PageUtils result = menuService.queryPage(page,menuEntity);

        return AjaxResult.success(result);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{menuId}")
    @PreAuthorize("@ss.hasPerm('system:menu:info')")
    public AjaxResult info(@PathVariable("menuId") Long menuId){
		MenuEntity menu = menuService.getById(menuId);

        return AjaxResult.success(menu);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @PreAuthorize("@ss.hasPerm('system:menu:save')")
    public AjaxResult save(@RequestBody MenuEntity menu){
		menuService.save(menu);

        return AjaxResult.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @PreAuthorize("@ss.hasPerm('system:menu:update')")
    public AjaxResult update(@RequestBody MenuEntity menu){
		menuService.updateById(menu);

        return AjaxResult.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @PreAuthorize("@ss.hasPerm('system:menu:delete')")
    public AjaxResult delete(@RequestBody Long[] menuIds){
		menuService.removeByIds(Arrays.asList(menuIds));

        return AjaxResult.success();
    }

}
